<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <input type="text" name="" id="">

</body>


<script>
  let data={
    value:'123'
  }
  let _value=''
  // 数据劫持 在没有return的时候 获取数据返回 undefined
  Object.defineProperty(data,'value',{
    get(){
      console.log('数据备货去啦');
      return _value
    },
    set(val){
      document.querySelector('input').value = val
      console.log(val,'输入框数值');
      _value = val
    }
  })
  // 1.绑定input事件
  document.querySelector('input').addEventListener('input',(e)=>{
    console.log(e.target.value);
    data.value = e.target.value
  })
</script>
</html>